cmake_minimum_required(VERSION 3.18)
project(clib C)

file(GLOB_RECURSE SRC_DIR_LIST "src/*.c")

link_libraries(pthread)

#add_library(clib SHARED ${SRC_DIR_LIST})

add_executable(clib main.c ${SRC_DIR_LIST})

macro(FIND_INCLUDE_DIR result current_dir)
    file(GLOB_RECURSE children "${current_dir}/*.h")
    set(dirlist "")
    foreach (child ${children})
        string(REGEX REPLACE "(.*)/src/(.*)" "\\2" HEADER_PATH ${child})
        message("${HEADER_PATH}")
        string(REGEX REPLACE "(.*)/(.*\\.h)" "\\1" HEADER_DIR_PATH ${HEADER_PATH})
        message("${HEADER_DIR_PATH}")
        install(FILES src/${HEADER_PATH} DESTINATION include/clib/${HEADER_DIR_PATH})
    endforeach ()
endmacro()

FIND_INCLUDE_DIR(INCLUDE_DIR_LIST src)

install(TARGETS clib LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
